package com.oceansoft.mobile.biz.api.service;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.oceansoft.mobile.biz.admin.entity.Wxjq;
import com.oceansoft.mobile.biz.admin.entity.WxjqMapper;
import com.oceansoft.mobile.common.Constant;
import com.oceansoft.mobile.common.base.entity.Pager;
import com.oceansoft.mobile.common.base.entity.Query;
import com.oceansoft.mobile.common.dao.ICommonDao;

@Service
public class ApiWxjqServiceImpl implements IApiWxjqService{
	@Resource
	private ICommonDao commonDao;
	
	@Override
	public Pager<Wxjq> queryWxjq(String title, int pageindex) {
		Query query = new Query();
		query.setRows(Constant.PAGE_SIZE);
		query.setPage(pageindex);
		String page_sql = String.format(
				"SELECT t.* FROM t_wxjq t WHERE T.title like ? and T.url != '' %s  ",
				Query.getPageSQL("T", query));
		String count_sql = String.format(
				"SELECT COUNT(*) FROM t_wxjq T WHERE T.title like ? and T.url != '' %s  ",
				Query.getCountSQL("T", query));
		List<Wxjq> list = new ArrayList<Wxjq>();
		list = commonDao.loadList(page_sql, new WxjqMapper(),"%"+title+"%");
		int total = commonDao.getCount(count_sql,"%"+title+"%");
		return new Pager<Wxjq>(total, query.getPage(), list);
	}

	@Override
	public Pager<Wxjq> queryWxjq2(String title, int pageindex, int areaId) {
		Query query = new Query();
		query.setRows(Constant.PAGE_SIZE);
		query.setPage(pageindex);
		String page_sql = String.format(
				"SELECT t.* FROM t_wxjq t WHERE T.area_id = ? and T.title like ? and T.url != '' %s  ",
				Query.getPageSQL("T", query));
		String count_sql = String.format(
				"SELECT COUNT(*) FROM t_wxjq T WHERE T.area_id = ? and T.title like ? and T.url != '' %s  ",
				Query.getCountSQL("T", query));
		List<Wxjq> list = new ArrayList<Wxjq>();
		list = commonDao.loadList(page_sql, new WxjqMapper(),areaId,"%"+title+"%");
		int total = commonDao.getCount(count_sql,areaId,"%"+title+"%");
		return new Pager<Wxjq>(total, query.getPage(), list);
	}
	
}
